/*
 * ResourceReservation.h
 *
 *  Created on: Nov 21, 2008
 *      Author: Ryan
 */

#ifndef RESOURCERESERVATION_H_
#define RESOURCERESERVATION_H_

#include "../../../OOInterface/Objects/Units/Unit.h"
#include <list>
#include <map>

typedef std::map< const OOInterface::Resource, float> ResourceMap;

class ResourceReservation
{
public:
	ResourceReservation();
	virtual ~ResourceReservation();

	void reserve( OOInterface::ConstUnitPtr builder, OOInterface::ConstCommandPtr command, ResourceMap resources );

	void updateTimers();

	const ResourceMap& getReservedResources() { return _reservedResources; }

	bool isBuilderReserved( OOInterface::ConstUnitPtr builder );


private:

	void releaseExpiredResources( OOInterface::ConstUnitPtr builder );

	typedef std::pair< OOInterface::ConstCommandPtr, ResourceMap > BuilderReservedResources;
	typedef std::list< std::pair< OOInterface::ConstUnitPtr, BuilderReservedResources > > BuilderResourceList;
	BuilderResourceList _resources;

	typedef std::pair< OOInterface::ConstUnitPtr, int > UnitTimerPair;
	typedef std::list< UnitTimerPair > Timers;
	Timers _timers;

	ResourceMap _reservedResources;

};

#endif /* RESOURCERESERVATION_H_ */
